package service;

import Utils.DruidUtils;
import domain.NewsType;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class NewsTypeService {

    public static List<NewsType> getNewsTypeServices(){
        List<NewsType> newsTypeList = null;

        try {
            // 执行sql语句
//            String sql = "select  from news_type";
            String sql = "select news_type_id as newsTypeId, news_type_name as newsTypeName from news_type;";

            QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
            newsTypeList = queryRunner.query(sql, new BeanListHandler<>(NewsType.class));

        }catch (Exception e){
            throw new RuntimeException(e);
        }

        return newsTypeList;
    }
}
